Stamp nested blocks and list items with source lines - #263
Merged
Conversation
Source-line tracking (sourceLines: true) previously stamped only the document's top-level blocks. Nested blocks parsed through rebuilt, re-indexed line arrays (blockquotes, divs, list items, footnotes, definition lists) could not be stamped because the local loop index no longer matched document coordinates. Thread an optional per-line map (local index to 0-based document line, -1 for synthetic lines) through parseBlocks() recursion and build it at every extraction site. Stamp nested blocks plus li/dt/dd nodes; keep raw HTML blocks and comments unstamped and never overwrite an author-set data-source-line attribute. Content parsed via the public parseBlockContent() helper carries no document positions, so it is mapped as unknown instead of mis-stamping local indices. Default output is unchanged; the map bookkeeping in the default case is below measurement noise on container-heavy documents.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #263 +/- ##
=========================================
Coverage 92.37% 92.37%
- Complexity 3643 3660 +17
=========================================
Files 109 109
Lines 10307 10379 +72
=========================================
+ Hits 9521 9588 +67
- Misses 786 791 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #262.
What
Extends opt-in source-line tracking (
sourceLines: true) from top-level blocks to nested blocks: content inside blockquotes, divs, list items, footnotes, and definition lists is now stamped withdata-source-linetoo, along with<li>,<dt>, and<dd>nodes themselves.Why
Editor scroll-sync needs dense anchors. With top-level-only stamping, a document that is one long list or blockquote yields a single anchor, so sync inside it degrades to interpolation over the whole container. Now every item and nested block is an anchor.
How
parseBlocks()/parseBlocksImpl()accept an optional per-line map (local index to 0-based document line,-1for synthetic lines that must not stamp). Built at every extraction site: blockquote prefix stripping, div fences, list item/sublist gathering (including the synthetic blank-line separator), footnotes, definition lists. Maps compose through arbitrary nesting (list in quote, etc.).li/dt/ddare created outside the block dispatch loop and stamped where constructed. An empty<dd>(term without definition) anchors to its term's line.data-source-lineattributes are never overwritten.parseBlockContent()helper (custom block callbacks) has no document positions and is mapped as unknown, so nested custom content is not mis-stamped with local indices (found by review).Behavior / performance
12 new tests (blockquotes incl. lazy continuation, divs, lists/sublists, synthetic separator, quote/list composition, footnotes, definition lists, author override, CRLF, custom blocks, default-off byte-identity).